import router from './router'

// 路由不重定向白名单
const whiteList = [
  '/login',
]

// 路由加载前
router.beforeEach(async (to, from, next) => {
  if (localStorage.getItem('userName')) {
    if (to.path === '/login') {
      next({ path: '/' })
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
    }
  }
})